import React, { useEffect } from 'react';
import "./index.less";
import { jsx as _jsx } from "react/jsx-runtime";
function Index(props) {
  var opMenu = props.opMenu,
    actions = props.actions,
    setOpMenu = props.setOpMenu;
  useEffect(function () {
    var handleClick = function handleClick(e) {
      if (opMenu.visible) {
        setOpMenu({
          visible: false
        });
      }
    };
    window.addEventListener('click', handleClick);
    return function () {
      window.removeEventListener('click', handleClick);
    };
  }, [opMenu.visible]);
  return opMenu.visible ? /*#__PURE__*/_jsx("div", {
    className: "pd-search-tree-op-menu",
    style: {
      top: "".concat(opMenu.top, "px"),
      left: "".concat(opMenu.left, "px")
    },
    children: /*#__PURE__*/_jsx("div", {
      className: "pd-search-tree-op-menu-popup",
      children: actions.map(function (item) {
        return /*#__PURE__*/_jsx("div", {
          className: "pd-search-tree-op-menu-item",
          onClick: function onClick(e) {
            e.stopPropagation();
            item.onClick(opMenu);
            setOpMenu({
              visible: false
            });
          },
          children: item.label
        }, item.key);
      })
    })
  }) : null;
}
export default Index;